package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.dao.CourseDao;
import com.zr.model.Course;
import com.zr.service.CourseService;

import net.sf.json.JSONObject;

public class UpdateCourseController extends HttpServlet{
	CourseService cs =new CourseService();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
		req.setCharacterEncoding("utf8");
		String course = req.getParameter("newcourse");
		//将取到的字符串转换成json对象
		JSONObject jso = JSONObject.fromObject(course);
		//将json对象转换为java对象
		Course newCourse = (Course) JSONObject.toBean(jso, Course.class);
		//添加新课程
		boolean flag = cs.updateCourse(newCourse);
		
		PrintWriter pw = resp.getWriter();
		pw.write(flag+"");
		
	}
}
